import httpRequest from '@/utils/request.js'

export function CreateCircle(data) {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'POST',
      url: '/circle',
      data
    })
      .then((res) => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleList(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'GET',
      url: '/circle',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleListByCategory(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'GET',
      url: '/circle/byCate',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleCategoryList() {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'GET',
      url: '/circle/category'
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleByUser(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'GET',
      url: '/circle/byUser',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleByStatus(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'GET',
      url: '/circle/byStatus',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function DeleteCircle(params) {
  return httpRequest.delete('/circle', { params: params })
}

export function GetCircleDetail(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      url: '/circle/detail',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleComments(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      url: '/circle/comments',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetLikeCircles(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      url: '/circle/like/page',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function GetCircleStared(params) {
  return new Promise((resolve, reject) => {
    httpRequest({
      url: '/circle/like',
      params
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function CreateCircleComment(data) {
  return new Promise((resolve, reject) => {
    httpRequest({
      method: 'POST',
      url: '/circle/comments',
      data
    })
      .then((res) => {
        resolve(res.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export function DeleteCircleComment(params) {
  return httpRequest.delete('/circle/comments', { params })
}

export function CircleLike(data) {
  return httpRequest.post('/circle/like', data)
}

export function CircleDislike(params) {
  return httpRequest.delete('/circle/like', { params: params })
}
